from matplotlib.animation import FuncAnimation
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.animation import FuncAnimation


class AnimatedScatter(FigureCanvas):
    def __init__(self):
        self.fig=Figure()
        self.ax=self.fig.add_subplot(111)

        # 创建图形和轴
        self.x = np.linspace(0, 2 * np.pi, 1000)
        self.line, = self.ax.plot(self.x, np.sin(self.x))
        super().__init__(self.fig)
        # 更新函数
        def update(frame):
            self.line.set_ydata(np.sin(self.x + frame / 10))
            return self.line,
        # 创建动画
        self.ani = FuncAnimation(self.fig, update, frames=100, blit=True)

        # 显示动画
        # plt.show()

